/*
 * @Author: zhang
 * @Date: 2025-03-31 10:04:05
 * @Description: 
 * @LastEditors: zhang
 * @LastEditTime: 2025-04-10 11:30:30
 */
export interface WoundedConfigItem {
    name?: string;
    id: number;
    type: number;
    icon: string;
    size?: [number, number];  // 可选属性，因为有些地形没有 size
    offset?: [number, number];  // 可选属性，因为有些地形没有 size
}

export interface WoundedConfig {
    woundedSize: WoundedConfigItem[]}

export class WoundedConfigManager {
    private static instance: WoundedConfigManager;
    private config: WoundedConfig | null = null;

    private constructor() {}

    public static getInstance(): WoundedConfigManager {
        if (!WoundedConfigManager.instance) {
            WoundedConfigManager.instance = new WoundedConfigManager();
        }
        return WoundedConfigManager.instance;
    }

    public async loadConfig(mapId:string): Promise<void> {
        try {
            const response = await fetch(`configs/woundedSize.json`);
            this.config = await response.json();
        } catch (error) {
            console.error('加载配置失败:', error);
        }
    }
    public getWoundedList(): WoundedConfigItem[] | null {
        if (!this.config) return null;
        return this.config.woundedSize;
    }


    public getWoundedConfig(id: number): WoundedConfigItem | null {
        if (!this.config) return null;
        return this.config.woundedSize.find(item => item.id == id) || null;
    }

    // 新增：获取完整的资源路径
    public getFullResourcePath(icon: string): string {
        if (!this.config) return icon;
        return "resources/map/role/" + icon;
    }
}

